home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / disksiz.com / SIZE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-04  |  10.9 KB  |  385 lines

  1. #include <stdio.h>
  2.  
  3.  
  4. extern int peek();
  5. /**********************************************************************/
  6.  
  7. main(quantity,parameter)
  8.     int quantity;
  9.     char *parameter[];
  10.     {
  11. int i, drive, orig_default;
  12. int disk_id;
  13. char drive_letter;
  14. unsigned long int lax, lbx, lcx, ldx;
  15. unsigned long int disk_used, disk_size, disk_free;
  16. unsigned long max_block, used_block, free_block;
  17. struct regval {int ax,bx,cx,dx,si,di,ds,es;} srv;
  18.  
  19. /************************************************************************/
  20. /*      Written by:  George H. Ford          Copyright, August 1990     */
  21. /*                   Severn, Maryland 21144                             */
  22. /*                                                                      */
  23. /*      Language:    Computer Innovations CI-86 Compiler                */
  24. /*                                    */
  25. /*      PUBLIC DOMAIN: Entered with source into PD as a learning tool.  */
  26. /*                                                             */
  27. /*      Some older computers using MS-DOS versions either did not support*/
  28. /*      or had a problem with int21H function 36H for other than the    */
  29. /*      default drive.  DX on return would be messed up, incorrect.     */
  30. /*      Therefore, the steps of this program have been set to avoid this*/
  31. /*      problem by switching default disks then back again:             */
  32. /*              get disk from command line                    */
  33. /*              get current default disk                                */
  34. /*              set default to command line disk                        */
  35. /*              get drive size info  and type                           */
  36. /*              set default back to original at start of program        */
  37. /*                                                             */
  38. /*     Make use of interrupt function 36H:                */
  39. /*        Entry: AH = 36H ,  DL = drive (0 - default, 1 = A, etc. */
  40. /*                                    */
  41. /*        Exit:  AX = FFFFH on error (bad drive designator)       */
  42. /*               AX = sectors per allocation unit            */
  43. /*               BX = number of free allocation units on drive    */
  44. /*               CX = bytes per sector                */
  45. /*               DX = total number of allocation units on drive   */
  46. /*                                    */
  47. /*    And interrupt function 1CH:                    */
  48. /*        Entry: AH = 1CH , DL = drive (0 - default, 1 = A, etc.  */
  49. /*                                    */
  50. /*        Exit:  AL = number of sectors per cluster               */
  51. /*               DS:BX = segment:offset of FAT identification byte*/
  52. /*               CX = size of physical sector (in bytes)          */
  53. /*               DX = number of clusters for drive                */
  54. /*                                    */
  55. /************************************************************************/
  56. srv.ax = 0x1900;
  57. sysint(0x21,&srv,&srv);   /* perform get orig_default drive */
  58. orig_default = 0x00ff & srv.ax;  /* drive 0 == a */
  59.  
  60. srv.ax = 0x0e00;
  61. srv.dx = drive = 0x0000;  /* dl has drive, 0 == a */
  62. if(quantity >= 2)
  63.   {
  64.   strncpy(&drive_letter, parameter[1],1);
  65.   drive = 0x00ff & toupper(drive_letter);
  66.   if((drive >= 'A') && (drive <= 'Z'))
  67.     {
  68.     drive -= 65;
  69.     srv.dx = (0x00ff & drive);
  70.     sysint(0x21,&srv,&srv);  /* perform set new default drive */
  71.     }
  72.   else
  73.     {
  74.     printf("\n\nUSAGE:  size  drive_letter\b");
  75.     printf("\n\nwhere,  size == this program's runtime name");
  76.     printf("\n        drive_letter == A to Z drive designator");
  77.     printf("\n                        (if absent, default drive is used)");
  78.     goto user_msg;
  79.     }
  80.   }
  81.  
  82.  
  83. /*        Find Size info for default drive            */
  84. srv.ax = 0x3600;  /* use interrupt 21hsubfunction 36h */
  85. srv.bx = 0x0000;
  86. srv.cx = 0x0000;
  87. srv.dx = 0x0000;  /* use default drive */
  88.  
  89. sysint(0x21,&srv,&srv);
  90.  
  91. if (srv.ax == 0xFFFF)
  92. {
  93. printf(" SYSERR-INFO [SEEK ERROR]: Drive designator on size seek error.\n");
  94. goto aeoutprt;
  95. }
  96.  
  97. lax = srv.ax;
  98. lbx = srv.bx;
  99. lcx = srv.cx;
  100. ldx = srv.dx;
  101.  
  102. disk_size = ((ldx * lax ) * lcx);
  103. disk_free = ((lbx * lax ) * lcx);
  104. disk_used = disk_size - disk_free;
  105.  
  106. max_block  = disk_size / lcx;
  107. used_block = disk_used / lcx;
  108. free_block = disk_free / lcx;
  109.  
  110.  
  111. /* get drive FAT id to determine the type of drive */
  112. srv.ax = 0x1C00;
  113. srv.dx = 0x0000;  /* use default drive */
  114. sysint(0x21,&srv,&srv);
  115. disk_id = (peek(srv.bx,srv.ds) & 0x00ff);
  116.  
  117.  
  118.  
  119. printf("\n\n");
  120.  
  121. for(i = 1; i<=80; i++) {printf("*");}
  122. printf("\n");
  123.  
  124. printf("BYTESIZE Stat-> Disk Size: (%10ld)  Used: (%10ld)  Free: (%10ld)\n\n",\
  125.     disk_size, disk_used, disk_free);
  126. printf("Sector Blocks-> Total Max: (%10ld)  Used: (%10ld)  Free: (%10ld)\n",\
  127.         max_block, used_block, free_block);
  128.  
  129. for(i = 1; i<=80; i++) {printf("-");}
  130.  
  131. printf("\n");
  132. printf("Sectors per cluster  unit (clustersize):   %10ld\n",\
  133.         lax);
  134. printf("Number  of free cluster units  on drive:   %10ld\n",\
  135.         lbx);
  136. printf("Number of bytes per sector, this  drive:   %10ld  [Block Size]\n",\
  137.         lcx);
  138. printf("TOTAL number of cluster  units on drive:   %10ld\n",\
  139.         ldx);
  140. printf("\n");
  141.  
  142. printf(\
  143. ">>>>>>>>>>>>>>>>>>>>>>>>  Possible Drive Type(s)  <<<<<<<<<<<<<<<<<<<<<<<<"\
  144. ); printf("\n");
  145. printf(\
  146. "Sec.  Sec.  Trk.  Num.  Cls.  Disk  Media   Possible    Media   Tracks Per"\
  147. ); printf("\n"); printf(\
  148. "Size  Trak  Side  Head  Size   ID   Size   Type Media  Density     Inch"\
  149. ); printf("\n"); printf(\
  150. "__________________________________________________________________________"\
  151. ); printf("\n");
  152.  
  153. if(disk_size >  3500000) goto fixed_disk;
  154.  
  155. switch(disk_id)
  156.   {
  157.   case 0x00f0:
  158. printf(\
  159. " 512   18    80     2     1    F0  1.44MB   3.5 inch     HD        135"\
  160. ); printf("\n");
  161. printf(\
  162. " 512   18    80     2     1    F0  1.44MB  5.25 inch     HD         96"\
  163. ); printf("\n");
  164.        break;
  165.   case 0x00f8:
  166.        if( lcx == 512)
  167.          {
  168. printf(\
  169. " 512    9    80     1     2    F8   360KB   3.5 inch     SD        135"\
  170. ); printf("\n");
  171. printf(\
  172. " 512    9    80     1     2    F8   360KB  5.25 inch     SD         96"\
  173. ); printf("\n");
  174.      }
  175.      if( lcx == 1024)
  176.          {
  177.      if(disk_size < 300000)
  178.            {
  179. printf(\
  180. "1024    5    40     1     1    F8   200KB  5.25 inch     SD         48"\
  181. ); printf("\n");
  182.            }
  183.            else
  184.            {
  185.            if(disk_size < 500000)
  186.               {
  187. printf(\
  188. "1024    5    80     1     1    F8   400KB  5.25 inch     SD         96"\
  189. ); printf("\n");
  190. printf(\
  191. "1024    5    80     1     1    F8   400KB   3.5 inch     SD        135"\
  192. ); printf("\n");
  193.               }
  194.               else
  195.               {
  196.           if(disk_size < 900000)
  197.                  {
  198. printf(\
  199. "1024    5    80     2     1    F8   800KB  5.25 inch     SD         96"\
  200. ); printf("\n");
  201. printf(\
  202. "1024    5    80     2     1    F8   800KB   3.5 inch     SD        135"\
  203. ); printf("\n");
  204.                  }
  205.                  else
  206.                  {
  207.                  if(disk_size < 140000)
  208.                     {
  209. printf(\
  210. "1024    8    80     2     1    F8  1.28MB  5.25 inch     HD         96"\
  211. ); printf("\n");
  212.                     }
  213.                  }
  214.               }
  215.            }
  216.          }
  217.        break;
  218.   case 0x00f9:
  219.     if(lcx == 512)
  220.            {
  221.            if(lax == 1)
  222.               {
  223.               if(disk_size < 800000)
  224.                  {
  225. printf(\
  226. " 512    9    80     2     1    F9   720KB   3.5 inch     SD        135"\
  227. ); printf("\n");
  228. printf(\
  229. " 512    9    80     2     1    F9   720KB   3.5 inch     SD        135"\
  230. ); printf("\n");
  231.                  }
  232.               else
  233.                  {
  234. printf(\
  235. " 512   15    80     2     1    F9  1.20MB  5.25 inch     HD         96"\
  236. ); printf("\n");
  237.                  }
  238.               }
  239.         if(lax == 2)
  240.               {
  241. printf(\
  242. " 512    9    80     2     2    F9   720KB   3.5 inch     SD        135"\
  243. ); printf("\n");
  244. printf(\
  245. " 512    9    80     2     2    F9   720KB  5.25 inch     SD         96"\
  246. ); printf("\n");
  247.               }
  248.             if(lax == 4)
  249.               {
  250. printf(\
  251. " 512    9    80     2     4    F9   720KB  5.25 inch     SD         96"\
  252. ); printf("\n");
  253.               }
  254.            }
  255.         if(lcx == 1024)
  256.            {
  257. printf(\
  258. "1024    5    40     2     1    F9   400KB  5.25 inch     SD         48"\
  259. ); printf("\n");
  260.            }
  261.        break;
  262.   case 0x00fa:
  263. printf(\
  264. " 512    8    80     1     2    FA   320KB   3.5 inch     SD        135"\
  265. ); printf("\n");
  266. printf(\
  267. " 512    8    80     1     2    FA   320KB  5.25 inch     SD         96"\
  268. ); printf("\n");
  269.        break;
  270.   case 0x00fb:
  271.     if(lcx == 512)
  272.           {
  273.       if(lax == 2)
  274.              {
  275. printf(\
  276. " 512    8    80     2     2    FB   640KB   3.5 inch     SD        135"\
  277. ); printf("\n");
  278. printf(\
  279. " 512    8    80     2     2    FB   640KB  5.25 inch     SD         96"\
  280. ); printf("\n");
  281.          }
  282.            else
  283.              {
  284. printf(\
  285. " 512    8    80     2     4    FB   640KB  5.25 inch     SD         96"\
  286. ); printf("\n");
  287.              }
  288.          }
  289.        if(lcx == 1024)
  290.          {
  291. printf(\
  292. "1024   10    80     2     1    FB  1.60MB   3.5 inch     HD        135"\
  293. ); printf("\n");
  294. printf(\
  295. "1024   10    80     2     1    FB  1.60MB  5.25 inch     HD         96"\
  296. ); printf("\n");
  297.          }
  298.        break;
  299.   case 0x00fc:
  300. printf(\
  301. " 512    9    40     1     1    FC   180KB  5.25 inch     SD         48"\
  302. ); printf("\n");
  303.        break;
  304.   case 0x00fd:
  305.     if(lax == 1)
  306.           {
  307. printf(\
  308. " 512    9    40     2     1    FD   360KB  5.25 inch     SD         48"\
  309. ); printf("\n");
  310.           }
  311.        if(lax == 2)
  312.           {
  313. printf(\
  314. " 512    9    40     2     2    FD   360KB  5.25 inch     SD         48"\
  315. ); printf("\n");
  316.           }
  317.     if(lax == 4)
  318.           {
  319. printf(\
  320. " 128   26    77     1     4    FD   250KB    8  inch     SD         48"\
  321. ); printf("\n");
  322.           }
  323.        break;
  324.   case 0x00fe:
  325.     if(lcx == 128)
  326.           {
  327. printf(\
  328. " 128   26    77     1     4    FE   250KB    8  inch     SD         48"\
  329. ); printf("\n");
  330.       }
  331.     if(lcx == 512)
  332.        {
  333. printf(\
  334. " 512    8    40     1     1    FE   160KB  5.25 inch     SD         48"\
  335. ); printf("\n");
  336.       }
  337.     if(lcx == 1024)
  338.       {
  339. printf(\
  340. "1024    8    77     2     1    FE  1.23MB  5.25 inch     HD         96"\
  341. ); printf("\n");
  342. printf(\
  343. "1024    8    77     2     1    FE  1.23MB    8  inch     SD         48"\
  344. ); printf("\n");
  345.       }
  346.        break;
  347.   case 0x00ff:
  348.     if(disk_size < 400000)
  349.       {
  350. printf(\
  351. " 512    8    40     2     2    FF   320KB  5.25 inch     SD         48"\
  352. ); printf("\n");
  353.       }
  354.     else
  355.       {
  356. printf(\
  357. " 512    9    80     2     2    FF   720KB  5.25 inch     SD         96"\
  358. ); printf("\n");
  359.       }
  360.        break;
  361.   default:
  362.      printf("Drive type is indeterminate from FAT Drive ID: %04xH\n",disk_id);
  363.      break;
  364.   }
  365.  
  366. fixed_disk:
  367. if(disk_size >  3500000)
  368.   {
  369.   printf("\n***** OTHER POSSIBLE DRIVE TYPE:  Fixed Disk\n");
  370.   }
  371.  
  372.  
  373. for(i = 1; i<=80; i++) {printf("*");}
  374.  
  375. aeoutprt:    /* abort on error message output printed to screen */
  376.  
  377. srv.ax = 0x0e00;
  378. srv.dx = 0x00ff & orig_default;  /* set to orig default drive */
  379. sysint(0x21,&srv,&srv);
  380.  
  381. user_msg:    /* usage message abort point */
  382. exit(0);
  383. }
  384.  
  385.